//
//  Data.m
//  UI_homework
//
//  Created by 黄威 on 16/5/22.
//  Copyright © 2016年 黄威. All rights reserved.
//

#import "Data.h"
#import "Model.h"
@implementation Data




- (void)dealloc{
    
    [_DataArr release];
    [super dealloc];
}

+ (instancetype)Data{
    
    static Data *data = nil;
    
    if (data == nil) {
        
        data = [[Data alloc] init];
        data.DataArr = [data getDataFromJson];
    }
    
    return data;
    
}



#pragma mark - Private Function

- (NSArray *)getDataFromJson{
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"ActivityList" ofType:@"txt"];
    
    NSData *data = [NSData dataWithContentsOfFile:path];
    
    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    
    return [self getModelArrayFromDicArray:dic[@"events"]];
    
}


- (NSArray *)getModelArrayFromDicArray:(NSArray *)array{
    
    NSMutableArray *modelArr = [NSMutableArray array];
    
    for (NSDictionary *dic in array) {
        
        Model *model = [[Model alloc] init];
        [model setValuesForKeysWithDictionary:dic];
        [modelArr addObject:model];
        [model release];
        
    }
    
    return modelArr;
    
}


@end
